使用列表随机向频道发送消息



我在time.sleep上有一个频道列表和一个正在运行的后台线程。我的目标是从 list_of_msgs=[] 向来自 channel_list=[] 的随机通道发送一条随机消息。

这就是我填充频道列表的方式:

chan_list = []
        for server in self.bot.servers:
            for channel in server.channels:
                if channel.type == discord.ChannelType.text:
                    chan_list.append(channel)
        print(', '.join(map(str, chan_list))) ###for testing###

从列表send_message到另一个列表中的频道的正确方法是什么?

import random
random.choice(chan_list)

你试过这个吗?

最新更新