python - 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!
解决方案
推荐阅读
- git - 如何使用令牌从詹金斯连接到 gitlab?您必须使用带有“read_repository”的个人访问令牌
- javascript - Jinja 在发送到 data-* 属性时添加了不必要的双引号
- android - 我们能否在 Android 中使用 ARCore Augmeted 人脸找到人脸旋转(左侧/右侧)?
- c - 如何在C中首先应用抢占式最短作业算法
- java - Postgres 测试容器 - 如果存在级联,为什么要在删除表之前删除约束?
- excel - Excel VBA选择单元格出现错误1004选择范围类失败
- python - 将指定的 pandas 列转换为字典列表
- google-cloud-platform - 通过云监控 API 检查 YouTube Data API v3 的使用情况
- ruby - 在 Mac OS High Sierra 上安装 Ruby 错误
- javascript - 使用 Angular 从 HTTP 请求追溯推送数据点时,Chart.js 数据会倒退