【问题标题】:message.content or ctx.content not working in selfbotmessage.content 或 ctx.content 在 selfbot 中不起作用
【发布时间】:2021-10-16 23:21:36
【问题描述】:
@client.event
async def on_message(ctx):
    if ctx.author == client.user:
        return
  
    if client.get_guild(544102306740699136):
        channel = client.get_channel(875779623638663192)
   
    await channel.send(str(ctx.author.mention) + 'just send message in channel' + str(ctx.channel.mention) + ': ' + str(ctx.content))

【问题讨论】:

标签: python discord.py message


【解决方案1】:

你可以使用ctx.message.content:

@client.event
async def on_message(ctx):

if ctx.author == client.user: 
    return

if client.get_guild(544102306740699136): 
    channel = client.get_channel(875779623638663192)
    await channel.send("Message: " + ctx.message.content)

更多信息请见here

【讨论】:

  • 这不会改变任何事情。这实际上会引发错误。从什么时候on_messagectx 作为参数?它应该是discord.Message 实例,而不是commands.Context,并且discord.Message 没有message 属性。
  • 只是这样做了,但是用message 替换了ctx 并且没有结果它只是发送消息:没有message.content
【解决方案2】:

所以我刚刚找到了答案,代码是:

@client.event
async def on_message(message):
    if message.author == client.user:
        return
    async for message in message.channel.history(limit=1):
     channel = client.get_channel(569791029197144073)
    await channel.send(str (message.author.mention)  +   ' je poslao/la poruku u kanalu  '   +str(message.channel.mention)+': '+str            (message.content))```

【讨论】:

    猜你喜欢
    • 2022-07-31
    • 2021-01-12
    • 2022-12-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-02-15
    • 1970-01-01
    相关资源
    最近更新 更多