没有使用Discord.py Rewrite的命令响应 [英] No Command responses using Discord.py Rewrite

查看:69
本文介绍了没有使用Discord.py Rewrite的命令响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用下面的代码创建了一个不和谐的bot,但是当我在服务器中键入.8ball或.ping时,我没有响应,也没有收到任何错误消息.但是,当我键入"hello"时,确实得到了"Hi"的预期响应,因此我知道它已连接.我感到困惑,因为我已经检查了100次语法,看不到任何错误.

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')

推荐答案

发现解决方案证明on_message事件会导致问题:

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

这篇关于没有使用Discord.py Rewrite的命令响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆