【问题标题】:Discord.Py / Bot was working great at first. Now the bot is live but when I try to give a command, Nothing happens and it doesnt show any errorDiscord.Py / Bot 起初运行良好。现在机器人已经上线,但是当我尝试发出命令时,什么都没有发生,也没有显示任何错误
【发布时间】:2021-12-03 07:54:02
【问题描述】:

我的代码应该可以正常工作吗?因为它以前做得很好。现在在我开始运行代码之后。并输入和转发消息。它不会再发送它了。并且获得频道名称而不是获得频道ID会更好吗?如果获取频道 ID 更好,我应该用 if channel.name in 替换什么? , 如果我的代码没问题,这是否意味着问题出在 discod 权限上?

@commands.has_permissions(kick_members=True)
async def alert(ctx, *, msg): #ALERT
    for guild in client.guilds:
        role = get(guild.roles, name = 'RayGunOptions Alerts') # roles
        for channel in guild.channels:
            if channel.name in ('????????????????????????-????????????????????????','gunvir-gay'):  # change for the list of channel names you got in your discord server
                one = Button(style=ButtonStyle.URL, label='Twitter', url="https://twitter.com/RayGunsOptions")
                two = Button(style=ButtonStyle.URL, label='Discord', url="https://discord.gg/6Fh4MTZN")
                three = Button(style=ButtonStyle.URL, label='Trading Journal', url="https://tradingjournal.com") 
                embed=discord.Embed(title= ':moneybag: **Option Alert** :moneybag:', description= (msg), url='https://twitter.com/RayGunsOptions', color=0x33FF9F, timestamp=datetime.datetime.utcnow())
                """embed.set_author(name="Crypto Alert", icon_url = ctx.author.avatar_url)""" #Top left name # IGNORE
                embed.set_thumbnail(url='https://pbs.twimg.com/profile_images/1383574983645962246/kD6PNI_L_400x400.jpg')
                embed.set_footer(icon_url = ctx.author.avatar_url, text='Powered by Duck Programming',)
                await channel.send(f"{role.mention}")                 
                await channel.send(embed=embed)
                await channel.send(
                    '**  **',
                    components=[
                        [one,]
                    ]
                )

【问题讨论】:

标签: python discord.py


【解决方案1】:

如果您的代码中有on_message_function,请在最后添加:

await self.bot.process_commands(message) # or client if you don't use bot

来源:https://discordpy.readthedocs.io/en/stable/faq.html?highlight=on_message#why-does-on-message-make-my-commands-stop-working

另外,如果你的命令不在你的 cog 中,请不要这样做:

commands.command()

改为:

bot.command() #or client.command()

【讨论】:

  • 我的代码中没有 on_message 代码行..
猜你喜欢
  • 1970-01-01
  • 2012-09-10
  • 1970-01-01
  • 1970-01-01
  • 2016-05-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多