0

Okay so I have this code, but when I try to use $announce, it doesn't write Hello back. In fact, it isn't responding to anything I put under the async def. How come?

I feel that I've done everything correctly, and the tutorials are for rewrite and up which I'm using.

import discord
from discord.ext import commands
import os
import time
import random
import weather
from weather import Weather, Unit

prefix = '$'
client = commands.Bot(command_prefix = prefix)
clattr = discord.Client()


@client.event
async def on_ready():
        await client.change_presence(status = discord.Status.online, activity = discord.Game('have a nice day!'))
        print("Bot is now online!")


@client.event
async def on_message(message):
  if message.content.startswith("$hello"):
    await message.channel.send(f"""Hi""")
    await message.channel.send(f"""Hi""")
    await message.channel.send(f"""Hi""")
    await message.channel.send(f"""Hi""")
    await message.channel.send(f"""Hi""")
    await message.channel.send(f"""Hi""")
    await message.channel.send(time())
  if message.content.startswith("$dm"): 
    user = client.get_user(393921960817721355)
    dm_channel = user.dm_channel
    if (dm_channel==None):
      dm_channel = await user.create_dm()
    await dm_channel.send(f"""Hello!""")
  if message.content.startswith("$servers"):
    await message.channel.send(clattr.guilds)
  if message.content.startswith("$help"):
    await message.channel.send(f"""This is the vanceBot. Made by vance and OYOHO#5964 (xray#4398 helped as well).\nThese are the current commands:\n$hello, which says "Hi" a few times \n$dm, which DMs a person\n$servers, which displays the number of servers that the bot is on\n$leave, to get the bot to leave\n$help, this command.\nThe prefix is $.""")
  if message.content.startswith("$pinghelp"):
    await message.channel.send(f"""||@everyone|| This is the vanceBot. Made by vance and OYOHO#5964 (xray#4398 helped as well).\nThese are the current commands:\n$hello, which says "Hi" a few times \n$dm, which DMs a person\n$servers, which displays the number of servers that the bot is on\n$leave, to get the bot to leave\n$help, this command.\nThe prefix is $.""")


@client.command()
async def announce(ctx, announcement):
  await ctx.send(f"""Hello""")




TOKEN = os.environ.get("DISCORD_BOT_SECRET")
client.run(TOKEN)
eyllanesc
  • 235,170
  • 19
  • 170
  • 241
Infiniwave
  • 537
  • 6
  • 20

1 Answers1

0

I changed your code as below, but be sure that discort.py is in the same folder with this code. If you get error please share the error/warning in your entry, it will help.

from discord import *
from discord.ext import commands
import os
import time
import random
import weather
from weather import Weather, Unit

prefix = '$'
client = commands.Bot(command_prefix = prefix)
clattr = Client()


@client.event
async def on_ready():
        await client.change_presence(status = Status.online, activity = Game('have a nice day!'))
        print("Bot is now online!")


@client.event
async def on_message(message):
  if message.content.startswith("$hello"):
    await message.channel.send(f"""Hi""")
    await message.channel.send(f"""Hi""")
    await message.channel.send(f"""Hi""")
    await message.channel.send(f"""Hi""")
    await message.channel.send(f"""Hi""")
    await message.channel.send(f"""Hi""")
    await message.channel.send(time())
  if message.content.startswith("$dm"): 
    user = client.get_user(393921960817721355)
    dm_channel = user.dm_channel
    if (dm_channel==None):
      dm_channel = await user.create_dm()
    await dm_channel.send(f"""Hello!""")
  if message.content.startswith("$servers"):
    await message.channel.send(clattr.guilds)
  if message.content.startswith("$help"):
    await message.channel.send(f"""This is the vanceBot. Made by vance and OYOHO#5964 (xray#4398 helped as well).\nThese are the current commands:\n$hello, which says "Hi" a few times \n$dm, which DMs a person\n$servers, which displays the number of servers that the bot is on\n$leave, to get the bot to leave\n$help, this command.\nThe prefix is $.""")
  if message.content.startswith("$pinghelp"):
    await message.channel.send(f"""||@everyone|| This is the vanceBot. Made by vance and OYOHO#5964 (xray#4398 helped as well).\nThese are the current commands:\n$hello, which says "Hi" a few times \n$dm, which DMs a person\n$servers, which displays the number of servers that the bot is on\n$leave, to get the bot to leave\n$help, this command.\nThe prefix is $.""")


@client.command()
async def announce(ctx, announcement):
  await ctx.send(f"""Hello""")




TOKEN = os.environ.get("DISCORD_BOT_SECRET")
client.run(TOKEN)
furkanayd
  • 811
  • 7
  • 19
  • Okay I've tried it, it gives: Traceback (most recent call last): File "main.py", line 4, in from discord import * ModuleNotFoundError: No module named 'discord' Yes I have installed discord.py. – Infiniwave Nov 24 '19 at 15:03
  • What is your Python Version? Can you open Python IDE and run import discord print discord.__version__ If discord installed properly it will show the version. – furkanayd Nov 24 '19 at 17:19
  • discord 1.0.1 discord.py 1.2.4 Python 3.7 64bit – Infiniwave Nov 25 '19 at 23:34