【问题标题】:an issue with making a discord embed in python, no responses on command prompt nor discord在 python 中嵌入不和谐的问题,在命令提示符或不和谐上没有响应
【发布时间】:2020-12-31 23:07:24
【问题描述】:

我正在尝试制作一些机器人调用它们的“有趣”命令,并且我想嵌入它们。但是它没有吐出任何东西,甚至没有出现不和谐的错误,也没有出现在命令提示符上,这让我不知道如何改进代码。我还想实现一种使用成员的方法:commands.Greedy[discord.Members] 代码,这样我就可以找到该命令的目标,但我认为我需要先解决这个问题。关于如何做到这一点的任何建议? 我也很困惑,因为我使用.formatf 字符串来尝试使用参数,我也尝试使用message,但这给了我一个语法错误'错误'列表'对象没有属性'提到''。我真的无法理解命令上的文档,因为它们并没有真正给出任何实际代码的示例,而且我不擅长理解新东西。有人能解决这个问题吗?

from discord.ext import commands
import discord
bot= commands.Bot(command_prefix='0!')
@bot.event
async def on_message(message):
     if message.author == bot.user:
          return
     if message.content.startswith('Sample Text'):
          await message.channel.send('Sample Text')
@bot.command()
async def slap(ctx):
    embed = discord.Embed(color=0x00ff00, title='OH! Z E  S L A P !', description="ooh, that hurt.")
    embed.add_field(name="Man behind the slaughter:", value="test")
    await ctx.send(embed=embed)
bot.run('token here')```
-During this edit, when I just had the 'bot command' area, It seemed to have functioned still. This makes it even more confusing...

【问题讨论】:

  • 您能否更新您的问题,使您的代码为minimal, reproducible example?这可能是一个 on_message 事件停止你的命令,但不能说没有完整的例子。
  • 完成!我这样做了,我认为这是您所说的on_message,但我需要更多帮助和这部分的详细信息;~;
  • 您需要将await bot.process_commands(message) 添加到您的on_message 事件中。见here
  • 是的!非常感谢。

标签: python bots embed discord.py


【解决方案1】:

覆盖默认提供的on_message() 事件会禁止运行任何额外的命令。要解决此问题,请在 on_message() 事件的末尾添加 bot.process_commands(message) 行。

@bot.event
async def on_message(message):
     if message.author == bot.user:
          return
     if message.content.startswith('Sample Text'):
          await message.channel.send('Sample Text')

    await bot.process_commands(message)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-06-17
    • 2021-10-05
    • 1970-01-01
    • 2020-10-18
    • 2021-11-21
    • 2019-09-04
    • 2021-08-18
    相关资源
    最近更新 更多