【问题标题】:Sending messages to the first channel. Discord.py向第一个频道发送消息。不和谐.py
【发布时间】:2021-01-19 14:12:13
【问题描述】:

我需要这样做,以便当机器人加入新服务器时,它将特定消息写入第一个文本通道。

我试图做某事:

@bot.event
async def on_guild_join(guild):
    print("Join to " + guild.name)
    guild_to_audiocontroller[guild] = AudioController(bot, guild)
    await guild_to_audiocontroller[guild].register_voice_channel(guild.voice_channels[0])
    for guild in bot.guilds:
        await guild.text_channels[0].send(join_message)

但它不想工作,我该怎么办?

【问题讨论】:

  • “它不想工作”是什么意思?你有任何错误信息吗?
  • @Mr_Spaar 不,它只是忽略了这些行
  • 如果此代码有效,每次您的机器人加入服务器时,它都会将您的加入消息发送到它所属的每台服务器,这是故意的吗?
  • @derw 哦,不,我需要他只发送给他加入的那个人。你不知道怎么做?

标签: discord bots discord.py


【解决方案1】:

只要您的机器人拥有Send Messages 权限,您只需在加入时发送消息:

@bot.event
async def on_guild_join(guild):
    await guild.text_channels[0].send("I have joined the server")

【讨论】:

    猜你喜欢
    • 2020-04-07
    • 2020-05-07
    • 2020-10-01
    • 1970-01-01
    • 2021-05-08
    • 2020-07-14
    • 2021-06-28
    • 2020-11-06
    • 1970-01-01
    相关资源
    最近更新 更多