【发布时间】:2021-03-21 20:29:38
【问题描述】:
我一直在运行以下代码,经过各种更改后,即使确保已启用从服务器向用户发送消息的权限,机器人仍然不会向用户返回欢迎 dm。
import os
import discord
from dotenv import load_dotenv
load_dotenv()
TOKEN = os.getenv('DISCORD_TOKEN')# gets the token of the bot from the .env file
client = discord.Client()# makes and discord client
@client.event #client on the following event:
async def on_ready():
print(f'{client.user} has connected to Discord!')# tells us if the bot is connected
@client.event
async def on_member_join(member):
await member.create_dm()# creates an dm channel
await member.dm_channel.send( # sends the string given as argument to the channel created
f'Hiiiiiiiiiii {member.name}, welcomeeeeeeeee icyyyyyy here'
)
client.run(TOKEN)# runs client for the bot token in TOKEN
并且代码成功返回该机器人已连接到不和谐并且也在服务器中上线。
【问题讨论】:
标签: python-3.x discord bots discord.py