【问题标题】:Why doesn't python allow me to use 2 arguments in discord.py?为什么 python 不允许我在 discord.py 中使用 2 个参数?
【发布时间】:2020-01-20 02:36:10
【问题描述】:

好的,所以我为我的不和谐制作了一个过滤器。大约 2 小时后,我想出了如何删除该消息。

但我意识到我不能使用 2 个参数。

@bot.event
async def on_message(ctx,message):
if 'cancer' in message.content.lower():
    await message.delete()
    bad = discord.Embed(title='YOU SAID A NO NO WORD!!!', description ='Dont do that again or you\'ll 
    have some problems <a:Sippp:668488891820408862>', colour=discord.Color.red())
    await ctx.channel.send(embed=bad)

当我这样做时,我不能同时使用 ctx 和消息。有人可以帮帮我吗?

我重用这个和它与我的另一个问题相似的原因是因为它没有在那里解释,而且因为它不仅方便其他人了解,如果他们不是在寻找那个精确的问题。

【问题讨论】:

标签: python bots discord discord.py


【解决方案1】:

on_message 应该接受一个参数,即发送的消息 (docs here)。

如果您需要访问发送消息的频道,您可以使用message.channel (see channel attribute in the message section of the docs)。所以你的功能变成:

@bot.event
async def on_message(message):
if 'cancer' in message.content.lower():
    await message.delete()
    bad = discord.Embed(title='YOU SAID A NO NO WORD!!!', description ='Dont do that again or you\'ll 
    have some problems <a:Sippp:668488891820408862>', colour=discord.Color.red())
    await message.channel.send(embed=bad)

【讨论】:

    猜你喜欢
    • 2015-02-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-17
    • 1970-01-01
    • 2013-04-11
    • 1970-01-01
    相关资源
    最近更新 更多