问题
I have created a discord bot using the code below but when I type .8ball or .ping in the server, I get no response, nor do I get an error message of any kind. However, I do get the expected response of "Hi" when I type "hello" so I know it's connected. It's baffling me as I've checked the syntax 100 times and can't see any errors.
import discord
import random
from discord.ext import commands
bot = commands.Bot(command_prefix = '.')
@bot.command()
async def ping(ctx):
await ctx.send("PONG!")
#await ctx.send(f'pong {round(bot.latency * 1000)}ms')
@bot.event
async def on_message(message):
id = bot.get_guild(521372392132706328)
if message.content.find("hello") != -1:
await message.channel.send("Hi")
elif message.content == "users":
await message.channel.send(f"""# of Members {id.member_count}""")
@bot.command(aliases=['8ball'])
async def _8ball(ctx, *, question):
responses = [
"It is certain.",
"It is decidedly so.",
"Without a doubt.",
"Yes - definitely.",
"You may rely on it.",
"As I see it, yes.",
"Most likely.",
"Outlook good.",
"Yes.",
"Signs point to yes.",
"Reply hazy, try again.",
"Ask again later.",
"Better not tell you now.",
"Cannot predict now.",
"Concentrate and ask again.",
"Don't count on it.",
"My reply is no.",
"My sources say no.",
"Outlook not so good.",
"Very doubtful."]
await ctx.send(f'Question: {question}\nAnswer: {random.choice(responses)}')
bot.run('12345')
回答1:
Found the solution turns out the on_message event causes issues:
https://discordpy.readthedocs.io/en/latest/faq.html#why-does-on-message-make-my-commands-stop-working
来源:https://stackoverflow.com/questions/60049873/no-command-responses-using-discord-py-rewrite