【问题标题】:Discord bot bug not respondingDiscord 机器人错误没有响应
【发布时间】:2022-11-27 01:08:49
【问题描述】:

你好,我是 stackoverflow 的新手,我正在开发一个不和谐的机器人 但它不会仅在 mp 中对我的不和谐服务器中的命令做出反应

这是我的代码

`

from discord.ext import commands
TOKEN = "X"

bot = commands.Bot(command_prefix="!")

@bot.event
async def on_ready():
    print(f'{bot.user} succesfully logged in!')

@bot.event
async def on_message(message):
    # Make sure the Bot doesn't respond to it's own messages
    if message.author == bot.user: 
        return
    
    if message.content == 'hello':
        await message.channel.send(f'Hi {message.author}')
    if message.content == 'bye':
        await message.channel.send(f'Goodbye {message.author}')

    await bot.process_commands(message)


@bot.command()
async def test(ctx, *, arg):
    await ctx.send(arg)

def to_upper(argument):
    return argument.upper()
    
@bot.command()
async def up(ctx, *, content: to_upper):
    await ctx.send(content)
    
bot.run(TOKEN)

` 请帮我 IN a server : in a mp:

我尝试了很多东西 但没有任何效果我正在为我的朋友制作一个不错的机器人而且我是 discord.py 的菜鸟

【问题讨论】:

标签: python-3.x discord discord.py bots


【解决方案1】:

好的,所以,多个@bot.event 可能是个问题,尤其是当您要查找消息时。

你需要设置一个监听器。 我还看到你没有设置意图,所以你也需要这样做。

在寻找消息时,您会想要这样的东西:

@bot.listen()#this makes the bot only listen for the messages
async def on_message(message):
    # Make sure the Bot doesn't respond to it's own messages
    if message.author == bot.user: 
        return
    
    if message.content == 'hello':
        await message.channel.send(f'Hi {message.author}')
    if message.content == 'bye':
        await message.channel.send(f'Goodbye {message.author}')

还有一个额外的提示:使用ctx.channel.send("message") 而不是ctx.send("message")

【讨论】:

    猜你喜欢
    • 2021-05-25
    • 2023-02-10
    • 2021-03-11
    • 2022-10-24
    • 2021-02-01
    • 2022-12-15
    • 2019-01-12
    • 2019-08-14
    相关资源
    最近更新 更多