【发布时间】:2020-01-10 12:18:30
【问题描述】:
我正在尝试使用 Python 制作 Discord BOT。我正在创建不同类型的函数,现在我想创建一个函数,让 BOT 在有人加入服务器时在通用频道中发送消息
import discord
import random
from discord.ext import commands
token = 'BOT_TOKEN'
client = commands.Bot(command_prefix = '!')
@client.event
async def on_ready():
print(f'{client.user.name} is now ready')
@client.command(aliases = ['ask', 'chiedi'])
async def _ask(ctx, *, question):
file_object = open("quotes.txt")
quotes = file_object.readlines()
file_object.close()
rnd = random.choice(quotes)
await ctx.send(rnd)
@client.event
async def on_message(message):
author = message.author
content = message.content
log = '{}: {}'.format(author, content)
with open("logs.txt", "a+") as my_file:
my_file.write(log + "\n")
my_file.close()
'''
func print_msg
once the user joins the server
print message to greet him
'''
client.run(token)
我希望输出类似于“用户名已加入我们的服务器!欢迎。”
【问题讨论】:
-
请更具体一些,并提供您完成的工作的代码 sn-ps 以便确定问题范围。
-
我编辑了你的帖子; 不要向任何人展示您的机器人令牌。拥有您的机器人令牌的人可以访问您的整个机器人。
-
我知道,这是一个不同的令牌
标签: python discord discord.py pypi