所以我想向我的机器人所在的所有服务器发送一个公告。我在 github 上找到了这个,但它需要一个服务器 id 和一个频道 id。
@bot.event
async def on_ready():
server = bot.get_server("server id")
await bot.send_message(bot.get_channel("channel id"), "Test")
Run Code Online (Sandbox Code Playgroud)
我也发现了一个类似的问题,但它在 discord.js 中。它说的是默认频道,但是当我尝试时:
@bot.event
async def on_ready():
await bot.send_message(discord.Server.default_channel, "Hello everyone")
Run Code Online (Sandbox Code Playgroud)
它给了我错误:目标必须是频道、私人频道、用户或对象
每当机器人被邀请到服务器时,我都想发送一条消息。然后它应该写一些类似的东西:“你好,这是我的不和谐机器人”
到目前为止,我有这段代码,它不会产生错误,但也不会发送消息。
@bot.event
async def on_server_join(ctx):
for guild in bot.guilds:
for channel in guild.text_channels:
if channel.permissions_for(guild.me).say:
await ctx.message.channel.send('Hello! \n')
break
Run Code Online (Sandbox Code Playgroud)