Discord.py bot that executes responses based on specific role [duplicate]












0
















This question already has an answer here:




  • How to check if a user has a specific role in on_message?

    1 answer




My python script:



import discord

TOKEN = 'X'

client = discord.Client()

@client.event
async def on_message(message):
# we do not want the bot to reply to itself
if message.author == client.user:
return

if message.content.startswith('!test'):
msg = "This message is a test".format(message)
await client.send_message(message.channel, msg)

if message.content.startswith('!admin'):
msg = "This command can be executed only as the owner".format(message)
await client.send_message(message.channel, msg)

@client.event
async def on_ready():
print('Logged in as')
print(client.user.name)
print(client.user.id)
print('------')

client.run(TOKEN)


For my discord bot I want to make it so that !test can be used by everyone and the bot would respond with "This message is a test". In addition, I want !admin to only be executed by the owner role and the bot would only respond with "This command can be executed only as the owner" or else it will reply with "Sorry you do not have a permission to use this command". How can I achieve this?










share|improve this question













marked as duplicate by Patrick Haugh python
Users with the  python badge can single-handedly close python questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 20 '18 at 23:39


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.



















  • What do you know about the owner role? It's id, its name, etc...

    – Patrick Haugh
    Nov 20 '18 at 20:35











  • Let me rephrase instead of using the owner role, how would I make it so that the command can only be executed when the user has the role "member"?

    – Ajay Shah
    Nov 20 '18 at 22:45
















0
















This question already has an answer here:




  • How to check if a user has a specific role in on_message?

    1 answer




My python script:



import discord

TOKEN = 'X'

client = discord.Client()

@client.event
async def on_message(message):
# we do not want the bot to reply to itself
if message.author == client.user:
return

if message.content.startswith('!test'):
msg = "This message is a test".format(message)
await client.send_message(message.channel, msg)

if message.content.startswith('!admin'):
msg = "This command can be executed only as the owner".format(message)
await client.send_message(message.channel, msg)

@client.event
async def on_ready():
print('Logged in as')
print(client.user.name)
print(client.user.id)
print('------')

client.run(TOKEN)


For my discord bot I want to make it so that !test can be used by everyone and the bot would respond with "This message is a test". In addition, I want !admin to only be executed by the owner role and the bot would only respond with "This command can be executed only as the owner" or else it will reply with "Sorry you do not have a permission to use this command". How can I achieve this?










share|improve this question













marked as duplicate by Patrick Haugh python
Users with the  python badge can single-handedly close python questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 20 '18 at 23:39


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.



















  • What do you know about the owner role? It's id, its name, etc...

    – Patrick Haugh
    Nov 20 '18 at 20:35











  • Let me rephrase instead of using the owner role, how would I make it so that the command can only be executed when the user has the role "member"?

    – Ajay Shah
    Nov 20 '18 at 22:45














0












0








0









This question already has an answer here:




  • How to check if a user has a specific role in on_message?

    1 answer




My python script:



import discord

TOKEN = 'X'

client = discord.Client()

@client.event
async def on_message(message):
# we do not want the bot to reply to itself
if message.author == client.user:
return

if message.content.startswith('!test'):
msg = "This message is a test".format(message)
await client.send_message(message.channel, msg)

if message.content.startswith('!admin'):
msg = "This command can be executed only as the owner".format(message)
await client.send_message(message.channel, msg)

@client.event
async def on_ready():
print('Logged in as')
print(client.user.name)
print(client.user.id)
print('------')

client.run(TOKEN)


For my discord bot I want to make it so that !test can be used by everyone and the bot would respond with "This message is a test". In addition, I want !admin to only be executed by the owner role and the bot would only respond with "This command can be executed only as the owner" or else it will reply with "Sorry you do not have a permission to use this command". How can I achieve this?










share|improve this question















This question already has an answer here:




  • How to check if a user has a specific role in on_message?

    1 answer




My python script:



import discord

TOKEN = 'X'

client = discord.Client()

@client.event
async def on_message(message):
# we do not want the bot to reply to itself
if message.author == client.user:
return

if message.content.startswith('!test'):
msg = "This message is a test".format(message)
await client.send_message(message.channel, msg)

if message.content.startswith('!admin'):
msg = "This command can be executed only as the owner".format(message)
await client.send_message(message.channel, msg)

@client.event
async def on_ready():
print('Logged in as')
print(client.user.name)
print(client.user.id)
print('------')

client.run(TOKEN)


For my discord bot I want to make it so that !test can be used by everyone and the bot would respond with "This message is a test". In addition, I want !admin to only be executed by the owner role and the bot would only respond with "This command can be executed only as the owner" or else it will reply with "Sorry you do not have a permission to use this command". How can I achieve this?





This question already has an answer here:




  • How to check if a user has a specific role in on_message?

    1 answer








python python-3.x bots discord.py






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 20 '18 at 19:47









Ajay ShahAjay Shah

2617




2617




marked as duplicate by Patrick Haugh python
Users with the  python badge can single-handedly close python questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 20 '18 at 23:39


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.









marked as duplicate by Patrick Haugh python
Users with the  python badge can single-handedly close python questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 20 '18 at 23:39


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.















  • What do you know about the owner role? It's id, its name, etc...

    – Patrick Haugh
    Nov 20 '18 at 20:35











  • Let me rephrase instead of using the owner role, how would I make it so that the command can only be executed when the user has the role "member"?

    – Ajay Shah
    Nov 20 '18 at 22:45



















  • What do you know about the owner role? It's id, its name, etc...

    – Patrick Haugh
    Nov 20 '18 at 20:35











  • Let me rephrase instead of using the owner role, how would I make it so that the command can only be executed when the user has the role "member"?

    – Ajay Shah
    Nov 20 '18 at 22:45

















What do you know about the owner role? It's id, its name, etc...

– Patrick Haugh
Nov 20 '18 at 20:35





What do you know about the owner role? It's id, its name, etc...

– Patrick Haugh
Nov 20 '18 at 20:35













Let me rephrase instead of using the owner role, how would I make it so that the command can only be executed when the user has the role "member"?

– Ajay Shah
Nov 20 '18 at 22:45





Let me rephrase instead of using the owner role, how would I make it so that the command can only be executed when the user has the role "member"?

– Ajay Shah
Nov 20 '18 at 22:45












1 Answer
1






active

oldest

votes


















0














This is how you can check if a message came from a server owner, no roles required:



if message.content.startswith('!admin'):
if (message.author == message.server.owner):
# do stuff
else:
msg = "This command can only be executed by the owner."
await client.send_message(message.channel, msg)


Of course, if you do this, you first need to make sure that private (direct) messages do not reach this statement, as they have no 'server' parameter. That can be done like this:



if (message.channel.type == discord.ChannelType.private):
return


All of this can be found in the discord.py documentation.






share|improve this answer
























  • Ok lets say that I want !admin to be used by the role "member" how would I make sure the message author is equal to the role "member."

    – Ajay Shah
    Nov 20 '18 at 22:43


















1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














This is how you can check if a message came from a server owner, no roles required:



if message.content.startswith('!admin'):
if (message.author == message.server.owner):
# do stuff
else:
msg = "This command can only be executed by the owner."
await client.send_message(message.channel, msg)


Of course, if you do this, you first need to make sure that private (direct) messages do not reach this statement, as they have no 'server' parameter. That can be done like this:



if (message.channel.type == discord.ChannelType.private):
return


All of this can be found in the discord.py documentation.






share|improve this answer
























  • Ok lets say that I want !admin to be used by the role "member" how would I make sure the message author is equal to the role "member."

    – Ajay Shah
    Nov 20 '18 at 22:43
















0














This is how you can check if a message came from a server owner, no roles required:



if message.content.startswith('!admin'):
if (message.author == message.server.owner):
# do stuff
else:
msg = "This command can only be executed by the owner."
await client.send_message(message.channel, msg)


Of course, if you do this, you first need to make sure that private (direct) messages do not reach this statement, as they have no 'server' parameter. That can be done like this:



if (message.channel.type == discord.ChannelType.private):
return


All of this can be found in the discord.py documentation.






share|improve this answer
























  • Ok lets say that I want !admin to be used by the role "member" how would I make sure the message author is equal to the role "member."

    – Ajay Shah
    Nov 20 '18 at 22:43














0












0








0







This is how you can check if a message came from a server owner, no roles required:



if message.content.startswith('!admin'):
if (message.author == message.server.owner):
# do stuff
else:
msg = "This command can only be executed by the owner."
await client.send_message(message.channel, msg)


Of course, if you do this, you first need to make sure that private (direct) messages do not reach this statement, as they have no 'server' parameter. That can be done like this:



if (message.channel.type == discord.ChannelType.private):
return


All of this can be found in the discord.py documentation.






share|improve this answer













This is how you can check if a message came from a server owner, no roles required:



if message.content.startswith('!admin'):
if (message.author == message.server.owner):
# do stuff
else:
msg = "This command can only be executed by the owner."
await client.send_message(message.channel, msg)


Of course, if you do this, you first need to make sure that private (direct) messages do not reach this statement, as they have no 'server' parameter. That can be done like this:



if (message.channel.type == discord.ChannelType.private):
return


All of this can be found in the discord.py documentation.







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 20 '18 at 21:06









Vojtěch StrnadVojtěch Strnad

11




11













  • Ok lets say that I want !admin to be used by the role "member" how would I make sure the message author is equal to the role "member."

    – Ajay Shah
    Nov 20 '18 at 22:43



















  • Ok lets say that I want !admin to be used by the role "member" how would I make sure the message author is equal to the role "member."

    – Ajay Shah
    Nov 20 '18 at 22:43

















Ok lets say that I want !admin to be used by the role "member" how would I make sure the message author is equal to the role "member."

– Ajay Shah
Nov 20 '18 at 22:43





Ok lets say that I want !admin to be used by the role "member" how would I make sure the message author is equal to the role "member."

– Ajay Shah
Nov 20 '18 at 22:43





Popular posts from this blog

鏡平學校

ꓛꓣだゔៀៅຸ໢ທຮ໕໒ ,ໂ'໥໓າ໼ឨឲ៵៭ៈゎゔit''䖳𥁄卿' ☨₤₨こゎもょの;ꜹꟚꞖꞵꟅꞛေၦေɯ,ɨɡ𛃵𛁹ޝ޳ޠ޾,ޤޒޯ޾𫝒𫠁သ𛅤チョ'サノބޘދ𛁐ᶿᶇᶀᶋᶠ㨑㽹⻮ꧬ꧹؍۩وَؠ㇕㇃㇪ ㇦㇋㇋ṜẰᵡᴠ 軌ᵕ搜۳ٰޗޮ޷ސޯ𫖾𫅀ल, ꙭ꙰ꚅꙁꚊꞻꝔ꟠Ꝭㄤﺟޱސꧨꧼ꧴ꧯꧽ꧲ꧯ'⽹⽭⾁⿞⼳⽋២៩ញណើꩯꩤ꩸ꩮᶻᶺᶧᶂ𫳲𫪭𬸄𫵰𬖩𬫣𬊉ၲ𛅬㕦䬺𫝌𫝼,,𫟖𫞽ហៅ஫㆔ాఆఅꙒꚞꙍ,Ꙟ꙱エ ,ポテ,フࢰࢯ𫟠𫞶 𫝤𫟠ﺕﹱﻜﻣ𪵕𪭸𪻆𪾩𫔷ġ,ŧآꞪ꟥,ꞔꝻ♚☹⛵𛀌ꬷꭞȄƁƪƬșƦǙǗdžƝǯǧⱦⱰꓕꓢႋ神 ဴ၀க௭எ௫ឫោ ' េㇷㇴㇼ神ㇸㇲㇽㇴㇼㇻㇸ'ㇸㇿㇸㇹㇰㆣꓚꓤ₡₧ ㄨㄟ㄂ㄖㄎ໗ツڒذ₶।ऩछएोञयूटक़कयँृी,冬'𛅢𛅥ㇱㇵㇶ𥄥𦒽𠣧𠊓𧢖𥞘𩔋цѰㄠſtʯʭɿʆʗʍʩɷɛ,əʏダヵㄐㄘR{gỚṖḺờṠṫảḙḭᴮᵏᴘᵀᵷᵕᴜᴏᵾq﮲ﲿﴽﭙ軌ﰬﶚﶧ﫲Ҝжюїкӈㇴffצּ﬘﭅﬈軌'ffistfflſtffतभफɳɰʊɲʎ𛁱𛁖𛁮𛀉 𛂯𛀞నఋŀŲ 𫟲𫠖𫞺ຆຆ ໹້໕໗ๆทԊꧢꧠ꧰ꓱ⿝⼑ŎḬẃẖỐẅ ,ờỰỈỗﮊDžȩꭏꭎꬻ꭮ꬿꭖꭥꭅ㇭神 ⾈ꓵꓑ⺄㄄ㄪㄙㄅㄇstA۵䞽ॶ𫞑𫝄㇉㇇゜軌𩜛𩳠Jﻺ‚Üမ႕ႌႊၐၸဓၞၞၡ៸wyvtᶎᶪᶹစဎ꣡꣰꣢꣤ٗ؋لㇳㇾㇻㇱ㆐㆔,,㆟Ⱶヤマފ޼ޝަݿݞݠݷݐ',ݘ,ݪݙݵ𬝉𬜁𫝨𫞘くせぉて¼óû×ó£…𛅑הㄙくԗԀ5606神45,神796'𪤻𫞧ꓐ㄁ㄘɥɺꓵꓲ3''7034׉ⱦⱠˆ“𫝋ȍ,ꩲ軌꩷ꩶꩧꩫఞ۔فڱێظペサ神ナᴦᵑ47 9238їﻂ䐊䔉㠸﬎ffiﬣ,לּᴷᴦᵛᵽ,ᴨᵤ ᵸᵥᴗᵈꚏꚉꚟ⻆rtǟƴ𬎎

Why https connections are so slow when debugging (stepping over) in Java?