Python 3.x Python将消息发送到多个通道
您好,我想从任何服务器使用通道id向多个通道发送消息 我使用了下面的代码,它可以很好地用于单个通道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
@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个位置参数,但当我使用下面的方法时,给出了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")