Python 我的discord机器人不会发送欢迎消息,但正在阅读其他消息。我正在使用discord.py
我正在尝试创建一个基本的discord机器人,目前正在尝试实现一个欢迎消息。我没有收到错误消息,它只是不起任何作用,如果我尝试在成员加入时将消息打印到控制台,则什么也不会发生。on_消息功能与on_就绪功能一起工作正常Python 我的discord机器人不会发送欢迎消息,但正在阅读其他消息。我正在使用discord.py,python,python-3.x,discord,Python,Python 3.x,Discord,我正在尝试创建一个基本的discord机器人,目前正在尝试实现一个欢迎消息。我没有收到错误消息,它只是不起任何作用,如果我尝试在成员加入时将消息打印到控制台,则什么也不会发生。on_消息功能与on_就绪功能一起工作正常 #bot import discord TOKEN = ('top secret token') client = discord.Client() intents = discord.Intents.default() intents.members = True @cl
#bot
import discord
TOKEN = ('top secret token')
client = discord.Client()
intents = discord.Intents.default()
intents.members = True
@client.event
async def on_ready():
print(f'{client.user} has connected to Discord!')
@client.event
async def on_message(message):
if message.author == client.user:
return
if message.content.startswith('$hello'):
await message.channel.send('Hello!')
@client.event
async def on_member_join(member):
await message.channel.send('Welcome!')
print('New User Detected')
client.run(TOKEN)
让我们看看。。。嗯
bot是否知道kwarg成员加入的事件中有哪些消息
和频道
。不,没有
消息和频道未在成员加入的中定义。首先,打开频道
channel=client.get\u channel(ChannelID)
这将为您提供想要发送消息的频道。
之后,我们只需使用channel.send(“message”)
发送消息
最终代码如下所示:
@client.event
async def on_member_join(member):
channel = client.get_channel(ChannelID)
await channel.send('Welcome!')
print('New User Detected')
让我们看看。。。嗯
bot是否知道kwarg成员加入的事件中有哪些消息
和频道
。不,没有
消息和频道未在成员加入的中定义。首先,打开频道
channel=client.get\u channel(ChannelID)
这将为您提供想要发送消息的频道。
之后,我们只需使用channel.send(“message”)
发送消息
最终代码如下所示:
@client.event
async def on_member_join(member):
channel = client.get_channel(ChannelID)
await channel.send('Welcome!')
print('New User Detected')
嗨,我用的是准确的代码,但它仍然没有给我一个信息。我还尝试将频道ID放在您有ChannelID的位置,但仍然无法发送。我已使其正常工作,这是权限问题。您好,我使用了确切的代码,但它仍然没有向我发送消息。我也试着把频道ID放在你有频道ID的地方,但还是不发送。我让它工作了,这是一个权限问题。