【问题标题】:Discord.py - Bot not sending messages & no error messagesDiscord.py - 机器人不发送消息并且没有错误消息
【发布时间】:2020-12-03 12:18:20
【问题描述】:

所以我正在为我的服务器制作自己的机器人,过了一段时间我终于找到了一个用于自动角色和角色分配的字符串。 然后我继续为机器人添加另一个字符串,只是回复“你好”。一旦我添加角色命令将不再起作用。一旦我把它拿出来,它就会再次起作用。 另一方面,我有一个 8ball 和一个掷骰子命令,可以使用和不使用 Hello 命令 我不知道是什么问题...

@client.event
async def on_member_join(member):
    channel = discord.utils.get(member.guild.channels, name='entrance')
    await channel.send(f'Welcome {member.mention} to Dreamy Castle! \n Please make sure to read the rules!')
    role = discord.utils.get(member.guild.roles, name="Peasants")
    await member.add_roles(role)

@client.event
async def on_message(message):
    if message.content.startswith('+acceptrules'):
        member = message.author
        role1 = discord.utils.get(member.guild.roles, name='The People')
        await member.add_roles(role1)

@client.event #this is the hello command
async def on_message(message):
    message.content.lower()
    if message.content.startswith('Hello Conny'):
        await message.channel.send('Hello!')

【问题讨论】:

标签: python discord discord.py


【解决方案1】:

对同一事件使用 ifelif 而不是 2 个不同的函数。

此外,您可能需要 commands.Bot 来获得功能齐全的命令机器人。

@client.event
async def on_message(message):
    if message.content.startswith('+acceptrules'):
        member = message.author
        role1 = discord.utils.get(member.guild.roles, name='The People')
        await member.add_roles(role1)
    elif message.content.lower().startswith("hello conny"):
        await message.channel.send("Hello!")
    await client.process_commands(message)

【讨论】:

  • 试过了,但它对任何一个命令都没有反应,我仍然没有收到错误......它只是没有做任何事情
  • 在on_message末尾添加await client.process_commands(message),查看修改后的代码
  • 我也试过了,但今天它对任何命令都没有反应......
  • 哦,我修复了一些小错误,它们都在工作!非常感谢!
  • 哦,我修复了一些小错误,它们都在工作!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-11-04
  • 2020-10-10
  • 2022-01-03
  • 2021-10-14
  • 2021-01-26
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多