如何解决使用on_member_join时,如何从漫游器获取消息以发送到所需的特定通道?
我正在尝试创建一个在成员加入公会时发送欢迎消息的机器人,但是我不知道如何将消息发送到我想要的特定频道。
到目前为止,我的代码:
import discord
from discord.ext import commands
import random
client = commands.Bot(command_prefix='.',case_insensitive=True)
@client.event
async def on_ready():
await client.change_presence(status=discord.Status.online,activity=discord.Game(': The Moon Song'))
print("bot is read to use")
@client.event
async def on_member_join(member: discord.Member = None):
name = member.display_name
embed = discord.Embed(title=(f'{member} has joined the guild! \nWelcome!'),description = 'please nativate to #rules and read all relavent information\nWe hope you enjoy your stay here <3',colour= 0xFFF0A1,)
embed.set_image(url='https://media.giphy.com/media/26xBz5092fHa8usx2/giphy.gif')
await member.send(embed=embed)
解决方法
您可以使用disocrd.utils.get
通过其ID获取#welcome频道。另外,无需使用(member: discord.Member = None):
,这是使用disocrd.utils.get
-
import discord
from discord.ext import commands
import random
client = commands.Bot(command_prefix='.',case_insensitive=True)
@client.event
async def on_ready():
await client.change_presence(status=discord.Status.online,activity=discord.Game(': The Moon Song'))
print("bot is read to use")
@client.event
async def on_member_join(member):
name = member.display_name
embed = discord.Embed(title=(f'{name} has joined the guild!\nWelcome!'),description = 'please nativate to #rules and read all relavent information\nWe hope you enjoy your stay here <3',colour= 0xFFF0A1,)
embed.set_image(url='https://media.giphy.com/media/26xBz5092fHa8usx2/giphy.gif')
await member.send(embed=embed)
channel = discord.utils.get(member.guild.text_channels,id="<your #welcome channel's ID>")
await channel.send(embed=embed)
参考-
,这就是我要做的
import discord
from discord.ext import commands
import random
client = commands.Bot(command_prefix='.',activity=discord.Game(': The Moon Song'))
print("bot is read to use")
@client.event
async def on_member_join(member: discord.Member = None):
channel = client.get_channel(ID) # Where ID is your welcome channel's ID.
name = member.display_name
embed = discord.Embed(title=(f'{member} has joined the guild! \nWelcome!'),)
embed.set_image(url='https://media.giphy.com/media/26xBz5092fHa8usx2/giphy.gif')
await channel.send(embed=embed)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。