【发布时间】:2019-10-15 14:06:18
【问题描述】:
我正在尝试创建一个新的 Discord 机器人,但在尝试创建一条向该机器人当前所在的所有 Discord 服务器公布的消息时出现问题。
我试图解决问题无济于事,这包括查找它、阅读文档,当然还有尝试新代码。
import discord
import asyncio
from discord.ext import commands
from discord.ext.commands import Bot
TOKEN = [REDACTED]
# client = discord.Client()
client = Bot("!")
@client.event
async def on_message(message):
# we do not want the bot to reply to itself
if message.author == client.user:
return
if message.content.startswith('!hello'):
@client.command(pass_context=True)
async def broadcast(ctx, *, msg):
for server in bot.guilds:
for channel in server.channels:
try:
await channel.send(msg)
except Exception:
continue
else:
break
我希望程序将我的消息发送到机器人当前所在的所有服务器。
例如:!你好,你好,这是一个公告!
应该触发 !hello 之后的消息在每个服务器上广播。
编辑:经过一些帮助后,我仍然遇到问题!现在的错误是执行命令后什么都没有出现,如果我再执行一次,它会出现错误:“命令广播已注册。”
【问题讨论】:
标签: python-3.x discord discord.py