python - 如何使用带有 python 的不和谐机器人发出欢迎消息?
问题描述
我是使用 python 制作不和谐机器人的新手,我想制作一个在有人加入服务器时显示欢迎消息的事件。
我试过这段代码
import discord
import random
from discord.ext import commands
alfred = commands.Bot(command_prefix = '!', description = "Hey!, I'm Alfred, How can I assist you?")
#EVENT
@alfred.event
async def on_ready():
print("I'm Alfred and I'm Online!")
@alfred.event
async def on_member_join(member):
embed=discord.Embed(title="Welcome!",description=f"{member.mention} Just Joined")
await message.channel.send(embed=embed)
但它没有用,甚至不和谐的文档也说该事件是“on_member_join”。
我真的希望你能帮助我:)
解决方案
试试这个,只需790274325533378682
用您的频道 ID替换
@alfred.event
async def on_member_join(member):
channel = alfred.get_channel(790274325533378682)
embed=discord.Embed(title="Welcome!",description=f"{member.mention} Just Joined")
await channel.send(embed=embed)
推荐阅读
- mysql - sql / mysql登录问题:o(
- java - java中流控制的布尔逻辑运算符
- node.js - 为什么 webpack 和 babel 都依赖 Node.js 运行?
- c# - 使用 mySerialPort.PortName () 时出错
- python-3.x - 如何使列表不连续三次重复相同的字符
- audio - 从 mp3 创建 HLS 可流式音频文件
- r - 知道两个dfm之间哪些单词不同的代码是什么?
- javascript - javascript布尔变量的值没有改变
- python - 如何将熊猫系列转换为数据框以与其他数据框合并
- react-native - 通过“Back”键在不同的堆栈之间来回移动