首页 > 解决方案 > Discord Bot 未按预期响应

问题描述

我用 python 编写了一个不和谐的机器人,当他加入服务器时,它应该问候一个成员,但它不是问候。

import os

import discord
from dotenv import load_dotenv

load_dotenv()
TOKEN = os.getenv('DISCORD_TOKEN','ODMyMTU..........')

client = discord.Client()

@client.event
async def on_ready():
    print(f'{client.user.name} has connected to Discord!')

@client.event
async def on_member_join(member):
    await member.create_dm()
    await member.dm_channel.send(
        f'Hi {member.name}, welcome to my Discord server!, Hello have a great time with us . By Anurag'
    )

client.run(TOKEN)

代码工作正常。

GodBot has connected to Discord!

标签: python

解决方案


推荐阅读