Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/logging/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 我的discord机器人不会发送欢迎消息,但正在阅读其他消息。我正在使用discord.py_Python_Python 3.x_Discord - Fatal编程技术网

Python 我的discord机器人不会发送欢迎消息,但正在阅读其他消息。我正在使用discord.py

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

我正在尝试创建一个基本的discord机器人,目前正在尝试实现一个欢迎消息。我没有收到错误消息,它只是不起任何作用,如果我尝试在成员加入时将消息打印到控制台,则什么也不会发生。on_消息功能与on_就绪功能一起工作正常

#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的地方,但还是不发送。我让它工作了,这是一个权限问题。