我是为不和谐而创建机器人的新手,我从不同的例子中获取代码,并在复制上写作。我想让机器人向服务器的一个新成员发送一个欢迎信息,但是当我邀请我的第二个帐户时,它不会发送任何东西。我已经包括了意图
import discord
from discord import Game
from discord.ext import commands
from discord.ext.commands import Bot
import asyncio
from webserver import keep_alive
import os
intents = discord.Intents.default()
intents.members = True
client = discord.Client(intents=intents)
client = commands.Bot(command_prefix='!')
@client.event
async def on_member_join(member):
channel = client.get_channel(channel_id=870695778593701939)
embed = discord.Embed(
title=f"Welcome {member.name}",
description=f"Thanks for joining {member.guild.name}!") # F-Strings!
embed.set_thumbnail(
url=member.avatar_url
) # Set the embed's thumbnail to the member's avatar image!
await channel.send(embed=embed)这就是我在电话上写的所有东西,我不知道我怎么能把这整段代码还回去,我很抱歉
发布于 2022-07-27 01:17:02
我猜I have included Intentions意味着您在bot构造函数和开发人员门户中添加了意图
所以首先
channel = client.get_channel(channel_id=870695778593701939)
channel_id不是参数名为id,而是一个位置参数,所以您只需执行client.get_channel(channel_id_here)就可以了,只需用通道id替换channel_id_here即可。
第二,当您在url=member.avatar_url函数中设置set_thumbnail时,如果成员没有化身,它将引发一个错误,所以我建议您检查用户是否有化身,如果用户不只是给它member.default_avatar_url,但是如果您使用discord.py 2.0 (主分支),那么使用member.display_avatar.url就会更容易
这只是一个建议,因为display_avatar返回用户/成员的化身,如果他们有一个或默认的不和谐给他们,所以不会引发错误。
https://stackoverflow.com/questions/73130791
复制相似问题