简体   繁体   English

Discord Bot Python - 向特定频道发送消息

[英]Discord Bot Python - Send message to specific channel

Im trying to create that bot that will send a message to a specific channel upon command (!ping channelid message)我正在尝试创建将根据命令向特定频道发送消息的机器人(!ping channelid 消息)

async def ping(message, canal, role):
    if message.author.guild_permissions.administrator:
        await message.channel.purge(limit=1) 

        channel = client.get_channel(f'{canal}')
        await channel.send(f'{role}')


client.run(token)

Somehow, i cant make it work.不知何故,我不能让它工作。 If i print the variable canal i get the channel id, however when executing the command i always get discord.ext.commands.errors.CommandInvokeError: Command raised an exception: AttributeError: 'NoneType' object has no attribute 'send'如果我打印变量 canal 我得到通道 ID,但是在执行命令时我总是得到 discord.ext.commands.errors.CommandInvokeError:命令引发异常:AttributeError:'NoneType' 对象没有属性 'send'

What im I doing wrong?我做错了什么?

remove the f strings.删除 f 字符串。 and set canal to only accept ints.并将运河设置为仅接受整数。 so canal: int or you can do channel = client.get_channel(int(canal)) According to your error you are never actually retrieving the channel.所以canal: int或者你可以做channel = client.get_channel(int(canal))根据你的错误,你从来没有真正检索过频道。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM