【问题标题】:Send message to channel at random using lists使用列表随机向频道发送消息
【发布时间】:2019-05-29 15:36:02
【问题描述】:

我在 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###

将列表中的消息发送到另一个列表上的频道的正确方法是什么?

【问题讨论】:

    标签: python python-3.x discord discord.py


    【解决方案1】:
    import random
    random.choice(chan_list)
    

    你试过了吗?

    【讨论】:

    • 优秀,甜美而简单。我是python的新手,所以学习这些东西很好!非常感谢,可以按我的需要工作!
    猜你喜欢
    • 1970-01-01
    • 2018-01-23
    • 2021-03-24
    • 2021-12-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-24
    • 1970-01-01
    相关资源
    最近更新 更多