我正在尝试创建一个机器人(该机器人通过DM)公开和私密地欢迎新用户加入Discord服务器,并且在用户离开服务器时向主持人频道发送消息。 / p>
我可以使welcome dm和welcome消息正常工作,但是当我在#Mod离开公告后添加代码时,没有任何反应。
import all necessary commands and libraries
import discord
import asyncio
import logging
@client.event
async def on_ready():
print('logged in as')
print(client.user.name)
print(client.user.id)
print('-----')
newUserDMMessage = "Welcome DM"
#Public Welcome
@client.event
async def on_member_join(member):
print("Recognised that a member called " + member.name + " joined")
await client.send_message(member, newUserDMMessage)
await client.send_message(discord.Object(id='CHANNELID'), 'Welcome!')
print("Sent message to " + member.name)
print("Sent message about " + member.name + " to #CHANNEL")
#Mod Leave Announcement
@client.event
async def on_member_remove(member):
print("Recognised that a member called " + member.name + " left")
await client.send_message(discord.Object(id='CHANNELID'), member.name + ' left')
print("Sent message to #CHANNEL")
client.run('Token')
答案 0 :(得分:1)
这是当前正在运行的代码。感谢Patrick Haugh的所有提示。
# import all necessary commands and libraries
import discord
import asyncio
import logging
@client.event
async def on_ready():
print('logged in as')
print(client.user.name)
print(client.user.id)
print('-----')
newUserDMMessage = "WELCOME!"
#Public Welcome
@client.event
async def on_member_join(member):
print("Recognized that " + member.name + " joined")
await client.send_message(member, newUserDMMessage)
await client.send_message(discord.Object(id='CHANNELID'), 'Welcome!')
print("Sent message to " + member.name)
print("Sent message about " + member.name + " to #CHANNEL")
#Mod Leave Announcement
@client.event
async def on_member_remove(member):
print("Recognized that " + member.name + " left")
await client.send_message(discord.Object(id='CHANNELID'), '**' + member.mention + '** just left.')
print("Sent message to #CHANNEL")
client.run('token')