Skip to main content
 首页 » 编程设计

python之消息中的不和谐 channel 链接

2024年10月17日8sharpest

我正在使用 discord.py 制作一个机器人,如果用户选择的关键字被提及,它会向用户发送直接消息。

一切正常,除了我只想将他们提到的 channel 添加到消息中。这是我的代码:

        print("SENDING MESSAGE") 
        sender = '{0.author.name}'.format(message) 
        channel = message.channel.name 
        server = '{0.server}'.format(message) 
        await client.send_message(member, server+": #"+channel+": "+sender+": "+msg) 

这会生成一条正确的消息,但消息的#channel 部分不是可点击的链接,如果我自己将它输入到聊天窗口中会是这样。我应该在消息中输入不同的对象吗?

请您参考如下方法:

在 Discord 中:有 channel 提及。 尝试这种方式,执行 message.channel.mention 而不是 message.channel.name 它应该能够在 PM 或任何地方链接一个 channel 。

来源:Discord Documentation