【问题标题】:Discord Fetch Random message from a Channel [Python]Discord 从频道中获取随机消息 [Python]
【发布时间】:2020-09-24 12:53:59
【问题描述】:

机器人应该从不同的频道获取随机消息并将其发送到发出命令的频道。

示例:我在#chat 中,它应该从#memes 获取随机消息并将其发布到我发出命令的#chat 中。

这是我编写的代码,但实际上不起作用。

@client.command()
async def meme(ctx, message_id, channel_id):
    guild = ctx.guild
    channel = guild.get_channel(int(672740818645417984))
    message = guild.fetch_message(random.choice(int(message_id)))
    message = await channel.fetch_message(int(message_id))
    await channel.send(message)

目前作为错误无法获取message_id

【问题讨论】:

    标签: python discord


    【解决方案1】:

    这行得通。

    @client.command()
    async def meme(ctx):
    
        channel = client.get_channel("channel id")
    
        allmes = []
        async for message in channel.history(limit=200):
            allmes.append(message)
    
        randoms = random.choice(allmes).content
    
        await ctx.send(randoms)
    

    【讨论】:

      猜你喜欢
      • 2020-12-23
      • 1970-01-01
      • 2019-03-18
      • 1970-01-01
      • 2021-07-06
      • 2021-03-24
      • 2021-06-05
      • 2021-05-14
      • 2021-08-19
      相关资源
      最近更新 更多