简体   繁体   English

特定频道中的 Discord 欢迎机器人

[英]Discord Welcome Bot in a specific channel

I want to welcome a New user in a specific channel but I am only able to DM them a message.我想在特定频道中欢迎新用户,但我只能向他们发送消息。 For example when I do member.send(newUserMessage) It DMs the new member a message however when I change it to await client.send_message(discord.Object(id='CHANNELID'), 'Welcome!') Nothing gets sent例如,当我执行member.send(newUserMessage)它会向新成员发送一条消息,但是当我将其更改为 await member.send(newUserMessage) client.send_message(discord.Object(id='CHANNELID'), 'Welcome!')没有发送任何消息

It either tells me that client has not attribute send_message or it doesnt send anything at all它要么告诉我客户端没有属性 send_message 要么它根本不发送任何东西

import os
import discord
import asyncio
from keep_alive import keep_alive
intents = discord.Intents(members=True)
client=discord.Client(intents=intents)


@client.event
async def on_member_join(member):
  print("Recognised that a member called " + member.name + " joined")

  await  member.send(newUserMessage)
  print("Sent message to " + member.name)

so if i understood your description correctly, you are trying to greet a new member by sending a message into a specific channel by using it's own ID?, it seems like you are using the rewrite version of discord.py, so it should be a little different.因此,如果我正确理解了您的描述,您是在尝试通过使用自己的 ID 向特定频道发送消息来迎接新成员吗?,似乎您正在使用 discord.py 的重写版本,所以它应该是一个有点不同。 First you have to specify the channel's ID, so then you can use the channel.send() command.首先,您必须指定频道的 ID,然后才能使用 channel.send() 命令。

@client.event
async def on_member_join(member):
  print("Recognised that a member called " + member.name + " joined")
  channel = client.get_channel(CHANNEL_ID_HERE)

  await channel.send('Welcome!')
  print("Sent message to " + member.name)

To get the channel ID, go to Discord > settings > advanced > Developer Mode and turn it on, then go to your discord server, right-click on the channel then click Copy ID, then go over to your code and paste it in. I hope i could help :).要获取频道 ID,请转到 Discord > 设置 > 高级 > 开发者模式并将其打开,然后转到您的 Discord 服务器,右键单击频道,然后单击复制 ID,然后转到您的代码并将其粘贴。我希望我能帮上忙:)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM