python - 我使用 discord.py 制作了一个 Welcomer 机器人。启动成功,但不向频道发送指定消息
问题描述
我使用 discord.py 制作了一个 Welcomer 机器人。它启动成功,但不向通道发送指定的消息。为什么是这样?
import discord
from discord.ext import commands
import asyncio
import datetime
bot = commands.Bot(command_prefix="/")
@bot.event
async def on_member_join(member):
emb = discord.Embed(
color = 0xff0000,
title = "{member.name}, welcome to my server!",
description = f"Total participants: {len(list(member.guild.members))}",
timestamp = datetime.datetime.utcnow()
)
channel = bot.get_channel(CHANNEL ID)
await channel.send(embed = emb)
bot.run ("BOT TOKEN")
解决方案
您的代码没有问题。我怀疑意图已关闭。转到Discord Developer Portal ,然后在您的机器人应用程序中打开Server Members Intent 。
on_member_join
如果没有关闭此意图,事件将不会执行。
编辑:
还可以尝试在代码中定义意图:
import discord
#....
from discord import Intents
intents = Intents.default()
intents.members = True
bot = commands.Bot(command_prefix="/", intents = intents)
推荐阅读
- asp.net - Telnet IP 地址 Ip
- r - 数据加载数据框作为承诺
- python-2.7 - Windows 10 上的 pipenv 什么都不做
- java - 处理在 scala 中的一个字段中具有空值的 json 字符串
- ajax - 在 lit-element Web 组件中获取异步数据
- reactjs - expect(onAgree).not.toHaveBeenCalled() 以及 expect(onAgree).toHaveBeenCalled() 的测试通过!如何?
- kotlin - springdoc-openapi:如何在 coRouter DSL 中使用 @RouterOperation
- amazon-web-services - aws configure get aws_access_key_id 的空结果
- java - 有没有办法在使用spring AOP执行某些代码行后调用通知方法
- python - 为 python 类实现通用和动态外观