python - 试图创建一个欢迎用户的 discord.py 机器人,但似乎不起作用
问题描述
我才开始环顾四周并弄清楚 discord.py bot 是如何工作的。尝试制作一个在某个频道中欢迎人们的机器人。但无论我做什么,它似乎都不起作用。代码执行并且 on_ready 触发。但它并没有像它应该的那样欢迎用户。有人可以帮忙吗?
import discord
from discord.ext import commands
from discord.ext.commands import Bot
from discord import Color
import asyncio
import datetime
intents = discord.Intents.default()
intents.members = True
client = discord.Client(intents=intents)
client=commands.Bot(command_prefix="-")
client.remove_command("help")
@client.event
async def on_ready():
print("Created by Goodboi")
print(client.user.name)
print("-----")
@client.event
async def on_member_join(member):
embed = discord.Embed(colour=0xe8744f,
description=f"Welcome to the discord server",)
embed.set_author(name=f"{member.mention}",icon_url=f"{member.avatar_url}")
embed.set_footer(text=f"{member.guild}",icon_url=f"{member.guild.icon_url}")
embed.timestamp = datetime.datetime.utcnow
channel = client.get_channel(id=) #usedid
await channel.send(embed=embed)
client.run('token') #usedtoken
解决方案
嗨,你必须得到这样的频道
@client.event
async def on_member_join(member):
embed = discord.Embed(colour=0xe8744f,
description=f"Welcome to the discord server",)
embed.set_author(name=f"{member.mention}",icon_url=f"{member.avatar_url}")
embed.set_footer(text=f"{member.guild}",icon_url=f"{member.guild.icon_url}")
embed.timestamp = datetime.datetime.utcnow()
channel = member.guild.get_channel(channel_id) #usedid
await channel.send(embed=embed)
推荐阅读
- ssas - PY YTD 计算的可以处理闰年 MDX 的度量
- c# - 如何让 VS Code 使用本地安装的 .NET Core?
- json - 使用 XSLT 提取 json 字段
- c# - JSON.NET:如何在初始流中获取 JSON 令牌的位置,以便更好地报告错误?
- nginx - 配置 nginx 以在 Debian 10 上运行 Jitsi
- html - 如何制作外观正确的 3D 2 面旋转立方体效果?
- sql - 作为表格的值列表
- ruby - Ruby Pronto 和 Gitlab 合并请求:没有内联注释
- go - 我可以使用 OpenCensus 跟踪子调用函数吗?
- laravel - 如何在 Laravel 中自定义 OrderBy