我想向机器人已加入的所有频道发送消息
def check(cnt):
while 1:
if hash_origin != str(subprocess.check_output(["md5sum",filename])[:-len(filename)-3])[2:-1] :
print("file destroyed alert!")
alert = 1
sleep(0.5)
当特定文件的哈希结果不同于原始文件时,我想向bot加入的所有不和谐频道发送消息。 我知道如何将响应消息发送到频道
@client.event
async def on_message(message):
使用此代码,对不对? 但是我想在某些事件发生时向机器人已加入的所有频道发送消息。
答案 0 :(得分:0)
要向机器人所在的每个频道发送消息,您必须执行以下操作:
@client.event
async def foo(bar): # change this to the event in which you wish to call it from
for guild in client.guilds:
for channel in guild.channels:
await channel.send(messagedata) # change messagedata to whatever it is you want to send.
答案 1 :(得分:0)
@client.event
async def foo(bar): # change this to the event in which you wish to call it from
for guild in client.guilds:
for channel in guild.channels:
await channel.send(messagedata) # change messagedata to whatever it is you want to send.
直接使用此代码时,发生了错误
AttributeError: 'CategoryChannel' object has no attribute 'send'
因为“ guild.channels”对象具有该机器人已加入的“所有频道”(包括文本,语音等)的列表。 因此,如果我想将文本消息发送到频道,请改用“ guild.text_channels”。 无论如何,感谢泰勒!