Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
211 views
in Technique[技术] by (71.8m points)

python - Code to @ discord bot and have it reply to you the prefix's and blah blah

import discord
from discord.ext import commands
#these are the modules needed
#Note: I don't want an if statement EX if "@Bot" == True
await.message.channel.send('words')

The reason Why I don't want this is because I tried it and when I command the Prefixhelp command the "word" is always in the second line of every command the bot can do, which is annoying so can anyone very quickly give me the code to have it not do that? Thank you.

question from:https://stackoverflow.com/questions/65849918/code-to-discord-bot-and-have-it-reply-to-you-the-prefixs-and-blah-blah

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

An easy way of getting a reply when some user tags your bot would be using a decorator in the bot instance:

from discord.ext import commands 

client = commands.Bot(command_prefix=commands.when_mentioned_or("!"))

But if you only want people to be able to simply send a message tagging your bot and it returns the prefix, you can simply check with the function mentioned_in to see if the bot is being mentioned in the message.

@client.event
async def on_message(message):
    if client.user.mentioned_in(message):
        await message.channel.send("The prefix is '!'")

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...