我正在尝试创建一个在成员加入公会时发送欢迎消息的机器人,但是我不知道如何将消息发送到我想要的特定频道。
到目前为止,我的代码:
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)
答案 0 :(得分:0)
您可以使用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)
参考-
答案 1 :(得分:0)
这就是我要做的
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):
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!'), 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 channel.send(embed=embed)