【问题标题】:Discord bot not wroking不和谐机器人不工作
【发布时间】:2021-01-17 05:25:55
【问题描述】:

我目前正在学习如何使用 python 制作 discord 机器人。但我一开始就卡住了。我的机器人没有响应

它没有显示错误。同样在不和谐服务器中,机器人正在在线显示。

但是当我运行guild.member_count 时,它会显示正确的成员数量。但是当我尝试通过guild.members 获取成员信息时,它只会在列表中显示我的机器人。

此外,如果我尝试在on_member_join() 中通过await member.create_dm() 发送消息,它不会发送任何消息。

我还给了机器人 administrator 权限,看看它的权限是否有问题,但还是一样。

下面是我的代码:

import discord

TOKEN = <MyToken> # I have replaced this with my actual token in the actual code

client = discord.Client()

@client.event
async def on_ready():
    guild = discord.utils.get(client.guilds, name=GUILD)
    print(
        f"{client.user} is connected to Discord!\n"
        f"Connected to {guild.name} (id: {guild.id}, members-count: {guild.member_count})"
        )
    members = '\n - '.join([member.name for member in guild.members])
    print(f'Guild Members:\n - {members}')


@client.event
async def on_member_join(member):
    await member.create_dm()
    await member.dm_channel.send(
        f"Hello {member.name}, Welcome to the test discord server!"
    )
    print(f"Welcomed {member.name}.\n")

client.run(TOKEN)

【问题讨论】:

    标签: python discord bots discord.py


    【解决方案1】:

    它只是在列表中显示我的机器人。

    Gateway Intents上查看此页面

    它不发送任何消息

    尝试使用

    await member.send(...)
    

    【讨论】:

    • 非常感谢。有效。几天以来,我一直在尝试解决此问题。我也无法在谷歌上找到任何东西。再次非常感谢。
    猜你喜欢
    • 2018-08-24
    • 2021-01-19
    • 2018-05-19
    • 2021-11-08
    • 2018-03-20
    • 2021-07-08
    • 2021-04-02
    • 2020-07-03
    • 2020-09-23
    相关资源
    最近更新 更多