Python不和谐机器人发送到多个渠道问题
Posted
技术标签:
【中文标题】Python不和谐机器人发送到多个渠道问题【英文标题】:Python discord bot send to multiple channels problem 【发布时间】:2020-07-12 00:34:24 【问题描述】:我在向多个频道发送消息时遇到问题。当我执行命令时,它只会发送到我写过的频道 8 次。这是我的代码:
import discord
import config
client = discord.Client()
@client.event
async def on_message(message):
id = client.get_guild(config.ID)
channels = [647074685535649802, 636901028478058497, 690272147050070158, 694196995887202375, 690276595578962177, 654662320735387648, 650381379892412426, 641704849196711976]
valid_users = ["Resadesker#1103"]
if str(message.author) in valid_users:
for channelo in channels:
if message.content.find("$spam") != -1:
print(channelo)
channel = client.get_channel(channelo)
print(channel)
await message.channel.send(message.content[message.content.find(' '):])
client.run(config.TOKEN)
【问题讨论】:
【参考方案1】:您似乎正在从message
向频道发送回复,试试这个:
@client.event
async def on_message(message):
id = client.get_guild(config.ID)
channels = [
647074685535649802,
636901028478058497,
690272147050070158,
694196995887202375,
690276595578962177,
654662320735387648,
650381379892412426,
641704849196711976,
]
valid_users = ["Resadesker#1103"]
if str(message.author) in valid_users:
for channelo in channels:
if message.content.find("$spam") != -1:
print(channelo)
channel = client.get_channel(channelo)
print(channel)
await channel.send(message.content[message.content.find(' '):])
【讨论】:
感谢您的回答,但是当我使用此类代码时出现错误: Traceback(最近一次调用最后一次):文件“D:\python\disbot\bot.py”,第 48 行,在 on_message 等待 channel.send(message.content[message.content.find(' '):]) 文件“C:\Program Files\Python38\lib\site-packages\discord\abc.py”,第 856 行,在发送数据 = await state.http.send_message(channel.id, content, tts=tts, embed=embed, nonce=nonce) raise Forbidden(r, data) discord.errors.Forbidden: 403 Forbidden (error code: 50013) : 缺少权限 机器人是否有权在所有频道中发帖? 谢谢!忘记设置机器人管理员权限!以上是关于Python不和谐机器人发送到多个渠道问题的主要内容,如果未能解决你的问题,请参考以下文章