Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x Python将消息发送到多个通道_Python 3.x_Discord.py - Fatal编程技术网

Python 3.x Python将消息发送到多个通道

Python 3.x Python将消息发送到多个通道,python-3.x,discord.py,Python 3.x,Discord.py,您好,我想从任何服务器使用通道id向多个通道发送消息 我使用了下面的代码,它可以很好地用于单个通道 @bot.command(pass_context=True) async def ping(ctx): channel = bot.get_channel("1234567890") await bot.send_message(channel, "Pong") 但是,当我尝试添加多个通道id时,i getting errorTypeError:get_channel()接受2

您好,我想从任何服务器使用通道id向多个通道发送消息

我使用了下面的代码,它可以很好地用于单个通道

@bot.command(pass_context=True)
async def ping(ctx):
    channel = bot.get_channel("1234567890")
    await bot.send_message(channel, "Pong")
但是,当我尝试添加多个通道id时,i getting error
TypeError:get_channel()接受2个位置参数,但当我使用下面的方法时,给出了3个位置参数

channel = bot.get_channel("1234567890", "234567890")

get\u channel
接受一个参数。您需要遍历所有ID并分别向每个ID发送消息

@bot.command(pass_context=True)
async def ping(ctx):
    channels_to_send = ["1234567890", "234567890"]
    for channel_id in channels_to_send:
        channel = bot.get_channel(channel_id)
        await bot.send_message(channel, "Pong")